-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scheduled tasks #655
Add scheduled tasks #655
Conversation
145892e
to
61e3df9
Compare
@joshbwlng Can we somehow track the actor who caused the job to be scheduled? I think when this is an async data manipulation we still need to track the user for all data changes / transactions that are performed 'later' |
61e3df9
to
bc73716
Compare
@fisehara Good point. How about using export const setup = async (tx: Db.Tx) => {
// Validate and schedule new scheduled jobs for future execution.
addPureHook('POST', apiRoot, 'scheduled_job', {
POSTPARSE: async ({ req, request }) => {
// Set defaults.
request.values.is_executed_by__user = req.user.id;
request.values.status = 'pending';
... |
@joshbwlng to not limit it to a user calling the API we should go and fetch the actorId like we do for the history tables in balena-api:
The actor will also identify any future usage of API keys that are maybe used for service-to-service integrations that are not strictly bound to a user entity. |
bc73716
to
153866d
Compare
@fisehara Nice, thanks, added a new field to the jobs sbvr and some bits to set the actor using basically the example you provided. |
@joshbwlng I have to review it again, but can you please add test cases for the scheduled jobs already? This will demonstrate how they will be used. |
b1c0ada
to
19a5652
Compare
[rcooke-warwick] This has attached https://jel.ly.fish/bd214614-d284-46b1-bd7e-1b0b17574605 |
20a4764
to
c623c6b
Compare
7fba214
to
fa09c11
Compare
2155986
to
6b3bcec
Compare
26c1d99
to
667289a
Compare
6739f20
to
44556fb
Compare
44556fb
to
45510e3
Compare
Moved to #739 |
Change-type: minor
[WIP] Add a new
tasks
vocabulary withjob
as its primary resource. Consumers can first register new job handlers withaddTaskHandler()
(similar toaddPureHook()
), and then schedule tasks for future execution by creatingtask
resources normally. Task executions are cancelled upon their resource counterpart being deleted. Limited retry/backoff logic included on execution failure. During startup, any pending jobs are either executed immediately or scheduled for future execution depending on theirstart_time
date.Note: Originally started with #654 which uses some existing migration functionality behind the scenes, but decided to try something that was completely decoupled from migrations. I'm looking for something to schedule and execute tasks, not migrations. While we could force the use of migrations, I'm not convinced it's the right decision - don't need async migrations/etc and wouldn't want to pollute migration tables with non-migration task records.
ToDo/Issues:
Example usage can be found in
test/07-tasks.test.ts
andtest/fixtures/07-tasks/task-handlers.ts
.